<template>
	<view class="editMobile">
		<view class="list">
			<view>
				<text>原手机号</text>
				<input type="text" v-model="from.phone" maxlength="11" placeholder="请输入新的手机号"/>
			</view>
			<view>
				<text>新手机号</text>
				<input type="text" v-model="from.newphone" maxlength="11" placeholder="请输入新的手机号"/>
			</view>
			<view>
				<text>验证码</text>
				<input type="text" v-model="from.msg" placeholder="请输入验证码">
				<view class="btn" @click="pageGetCode">{{getCodeText}}</view>
			</view>
		</view>
		<view class="submit" @click="C_submit">确定</view>
	</view>
</template>

<script>
	import yz from '@/common/yz.js'
	export default {
		data() {
			return {
				from:{
					phone:'',
					newphone:'',
					msg:''
				},
				getCodeText:'获取验证码'
			};
		},
		methods:{
			async pageGetCode(){
				let {phone,newphone,msg} = this.from
				if(!yz.isMobile(phone)){this.$u.toast('清输入正确的手机号');return}
				if(!yz.isMobile(newphone)){this.$u.toast('清输入正确的新手机号');return}
				
				if(this.getCodeText == '获取验证码'){
					this.$u.utils.getCode(this)
					// let smsCode = await this.$u.api.send_msg({mobile:phone})
					// console.log(smsCode,'smsCode');
				}
			},
			C_submit(){
				console.log(yz);
				let {phone,newphone,msg} = this.from
				if(!yz.isMobile(phone)){this.$u.toast('清输入正确的手机号');return}
				if(!yz.isMobile(newphone)){this.$u.toast('清输入正确的新手机号');return}
				if(!msg){this.$u.toast('请输入验证码');return}
				
				this.$u.post('/appuser/changePhone',{...this.from}).then(res=>{
					res.code == 0?uni.navigateBack():this.$u.toast(res.msg)
				})
			}
		}
		
	}
</script>

<style lang="scss">
	.list{
		width: 95%;
		margin: 20rpx auto;
		padding: 0 50rpx;
		background-color: #FFFFFF;
		border-radius:20rpx ;
		>view{
			display: flex;
			align-items: center;
			justify-content: space-between;
			height: 100rpx;
			border-bottom: 1px solid rgba(0,0,0,.05);
			.btn{
				border: 1px solid #3169E9;
				color: #3169E9;
				padding: 10rpx 20rpx;
				border-radius: 10rpx;
			}
			input{
				text-align: right;
			}
		}
	}
	.submit{
		padding: 20rpx;
		text-align: center;
		width: 80%;
	}
</style>
